<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="keywords" content="">
<meta name="description" content="">
<title>角色列表</title>
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
</head>

<body>
<!--_header 作为公共模版分离出去-->
<header class="navbar-wrapper" id="header">
    
</header>
<!--/_header 作为公共模版分离出去--> 

<!--_menu 作为公共模版分离出去-->
<aside class="Hui-aside" id="menu">
</aside>
<div class="dislpayArrow hidden-xs"> <a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a> </div>
<!--/_menu 作为公共模版分离出去-->

<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        管理员管理
        <span class="c-gray en">&gt;</span>
        <span id="mbx"></span>
        
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a> </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="text-c">
                <!-- <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:120px;">
                -
                <input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" style="width:120px;">
                <input type="text" class="input-text" style="width:250px" placeholder="输入管理员名称" id="" name=""> -->
                <!-- <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i>确定</button> -->
            </div>
            <div class="cl pd-5 bg-1 bk-gray mt-20" style="min-width: 900px">
                <span class="l">
                    <!-- <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> -->
                    <a href="javascript:;" onclick="role_add('添加角色','add.html','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a>
                </span>
                <span class="r">共有数据：<strong id="total"></strong> 条</span>
            </div>
            <div id="edatalist" style="min-width: 900px;">
                <table class="table table-border table-bordered table-bg">
                    <thead>
                        <tr class="text-c">
                            <th width="30px"><input type="checkbox" name="" value=""></th>
                            <th width="50px">ID</th>
                            <th width="120px">角色名称</th>
                            <th width="min-width:180px">权限id列表</th>
                            <th width="min-width:160px">用户列表</th>
                            <th width="80px">状态</th>
                            <th width="120px">备注</th>
                            <th width="100px">操作</th>
                        </tr>
                    </thead>
                    <tbody id="liebiao_box">

                    </tbody>
                </table>
            </div>
        </article>
    </div>
</section>

<!--_footer 作为公共模版分离出去--> 
<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script> 
<script type="text/javascript" src="../static/h-ui/js/H-ui.js"></script> 
<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.page.js"></script> 
<!--/_footer /作为公共模版分离出去--> 

<script  type="text/javascript" src="../static/js/admin.js"></script>
<script  type="text/javascript" src="../static/js/header.js?123"></script>
<script  type="text/javascript" src="../static/js/menu.js?1234"></script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="../lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="../lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript">
    $.ajax({
        url: "/ajax/admin_role/list",
        type: "GET",
        data: null,
        beforeSend: function (request) {
            request.setRequestHeader("authStr", window.localStorage.getItem("userId") + "-" + window
                .localStorage.getItem("token"));
        },
        success: function (data) {
            if (data.success == true) {
                console.log(data);
                var total = data.data.total;
                $("#total").text(total);
                roleList = data.data.list;
                var liebiao_str = "";
                /*计算栏目条数*/
                var count_tr = 0;
                roleList.forEach(elm_role => {
                    liebiao_str += '<tr class="text-c">';
                    liebiao_str += '<td><input type="checkbox" value="' + elm_role.id +
                        '" name="checkbox[]"></td>';
                    liebiao_str += '<td>' + elm_role.id + '</td>';
                    liebiao_str += '<td>' + elm_role.name + '</td>';
                    liebiao_str += '<td class="text-l">' + elm_role.permission + '</td>';
                    liebiao_str += '<td class="text-l">' + elm_role.usernames + '</td>';
                    if (elm_role.status==0) {
                        liebiao_str += '<td class="td-status"><span class="label radius">已停用</span></td>';
                    } else {
                        liebiao_str += '<td class="td-status"><span class="label label-success radius">已启用</span></td>';
                    }
                    liebiao_str += '<td>' + elm_role.note + '</td>';
                    liebiao_str += '<td class="f-14">';
                    liebiao_str +=
                        '<a title="编辑" href="javascript:;" onclick="role_edit(\'编辑信息\',\'add.html\',' +
                        elm_role.id +
                        ',\'800\',\'500\')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>';
                    liebiao_str +=
                        '<a title="删除" href="javascript:;" onclick="role_del(this,' + elm_role
                        .id +
                        ')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                    liebiao_str += '</td>';
                    liebiao_str += '</tr>';
                });
                $("#liebiao_box").append(liebiao_str);
            }
        }
    });
    
    /*
        参数解释：
        title	标题
        url		请求的url
        id		需要操作的数据id
        w		弹出层宽度（缺省调默认值）
        h		弹出层高度（缺省调默认值）
    */

    /*编辑数据-编辑*/
    function role_edit(title,url,id,w,h){
        url = url + '?action=edit&id=' + id;
        layer_show(title,url,w,h);
    }

    /*编辑数据-增加*/
    function role_add(title,url,w,h){
        url = url + '?action=add';
        layer_show(title,url,w,h);
    }

    /*编辑数据-删除*/
    function role_del(obj, id){
        layer.confirm('确认要删除吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type:"POST",
                url:"/ajax/admin_role/delete",
                data:{"id":id},
                dataType:"json",
                beforeSend:function(request){
                    request.setRequestHeader("authStr", window.localStorage.getItem("userId")+"-"+window.localStorage.getItem("token"));
                },
                success:function(data){
                    if(data.success==true){                       
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1, time:1000});
                    } else{
                        layer.msg(data.msg,{icon:5, time:1000});
                    }
                    return false;
                },
                error:function(e){
                    layer.msg("操作出错, 请稍后重试",{icon:5, time:1000})
                }
            });
        });
    }
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>